package ar.edu.unsam.algo3.plantasvszombies.wicket;

import ar.edu.unsam.algo3.plantasvszombies.ui.ApplicationModels.AlmanaqueAppModel;
import ar.edu.unsam.algo3.plantasvszombies.ui.ApplicationModels.JardinAppModel;
import ar.edu.unsam.algo3.plantasvszombies.wicket.MainPage;
import ar.edu.unsam.algo3.plantasvszombies.wicket.components.XOnChangeAjaxBehavior;
import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function0;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.uqbar.wicket.xtend.WicketExtensionFactoryMethods;
import org.uqbar.wicket.xtend.XAjaxLink;
import org.uqbar.wicket.xtend.XListView;

@SuppressWarnings("all")
public class AlmanaqueZombiePage extends MainPage {
  @Extension
  private WicketExtensionFactoryMethods _wicketExtensionFactoryMethods = new Function0<WicketExtensionFactoryMethods>() {
    public WicketExtensionFactoryMethods apply() {
      WicketExtensionFactoryMethods _wicketExtensionFactoryMethods = new WicketExtensionFactoryMethods();
      return _wicketExtensionFactoryMethods;
    }
  }.apply();
  
  private final AlmanaqueAppModel almanaqueApp = new Function0<AlmanaqueAppModel>() {
    public AlmanaqueAppModel apply() {
      AlmanaqueAppModel _almanaqueAppModel = new AlmanaqueAppModel();
      return _almanaqueAppModel;
    }
  }.apply();
  
  private final Form<Object> formZombies = new Function0<Form<Object>>() {
    public Form<Object> apply() {
      Form<Object> _form = new Form<Object>("formZombies");
      return _form;
    }
  }.apply();
  
  public AlmanaqueZombiePage(final JardinAppModel unJardinApp) {
    this.setJardinApp(unJardinApp);
    CompoundPropertyModel<AlmanaqueAppModel> _asCompoundModel = this._wicketExtensionFactoryMethods.<AlmanaqueAppModel>asCompoundModel(this.almanaqueApp);
    this.setDefaultModel(_asCompoundModel);
    Panel _menuNavegacion = this.menuNavegacion();
    this._wicketExtensionFactoryMethods.addChild(this, _menuNavegacion);
    this.crearTablaZombies();
    this.agregarAcciones();
    this.almanaqueApp.buscar();
  }
  
  public Component crearTablaZombies() {
    Component _xblockexpression = null;
    {
      XListView<Object> _xListView = new XListView<Object>("result");
      final XListView<Object> listaZombie = _xListView;
      final Procedure1<ListItem<Object>> _function = new Procedure1<ListItem<Object>>() {
        public void apply(final ListItem<Object> item) {
          Object _modelObject = item.getModelObject();
          CompoundPropertyModel<Object> _asCompoundModel = AlmanaqueZombiePage.this._wicketExtensionFactoryMethods.<Object>asCompoundModel(_modelObject);
          item.setModel(_asCompoundModel);
          Label _label = new Label("nombre");
          AlmanaqueZombiePage.this._wicketExtensionFactoryMethods.addChild(item, _label);
          Label _label_1 = new Label("defensa");
          AlmanaqueZombiePage.this._wicketExtensionFactoryMethods.addChild(item, _label_1);
          Label _label_2 = new Label("ataque");
          AlmanaqueZombiePage.this._wicketExtensionFactoryMethods.addChild(item, _label_2);
          Label _label_3 = new Label("descripcion");
          AlmanaqueZombiePage.this._wicketExtensionFactoryMethods.addChild(item, _label_3);
        }
      };
      listaZombie.setPopulateItem(_function);
      this._wicketExtensionFactoryMethods.addChild(this.formZombies, listaZombie);
      this._wicketExtensionFactoryMethods.addChild(this, this.formZombies);
      Component _setOutputMarkupId = this.formZombies.setOutputMarkupId(true);
      _xblockexpression = (_setOutputMarkupId);
    }
    return _xblockexpression;
  }
  
  public MarkupContainer agregarAcciones() {
    MarkupContainer _xblockexpression = null;
    {
      TextField<String> _textField = new TextField<String>("nombre");
      final TextField<String> txtNombre = _textField;
      XOnChangeAjaxBehavior _xOnChangeAjaxBehavior = new XOnChangeAjaxBehavior();
      final Procedure1<XOnChangeAjaxBehavior> _function = new Procedure1<XOnChangeAjaxBehavior>() {
        public void apply(final XOnChangeAjaxBehavior it) {
          final Procedure1<AjaxRequestTarget> _function = new Procedure1<AjaxRequestTarget>() {
            public void apply(final AjaxRequestTarget target) {
              AlmanaqueZombiePage.this.almanaqueApp.buscar();
              target.add(AlmanaqueZombiePage.this.formZombies);
            }
          };
          it.setOnUpdate(_function);
        }
      };
      XOnChangeAjaxBehavior _doubleArrow = ObjectExtensions.<XOnChangeAjaxBehavior>operator_doubleArrow(_xOnChangeAjaxBehavior, _function);
      this._wicketExtensionFactoryMethods.addBehavior(txtNombre, _doubleArrow);
      this._wicketExtensionFactoryMethods.addChild(this, txtNombre);
      XAjaxLink<Object> _xAjaxLink = new XAjaxLink<Object>("limpiar");
      final Procedure1<XAjaxLink<Object>> _function_1 = new Procedure1<XAjaxLink<Object>>() {
        public void apply(final XAjaxLink<Object> it) {
          final Procedure1<AjaxRequestTarget> _function = new Procedure1<AjaxRequestTarget>() {
            public void apply(final AjaxRequestTarget target) {
              AlmanaqueZombiePage.this.almanaqueApp.limpiar();
              target.add(txtNombre);
              target.add(AlmanaqueZombiePage.this.formZombies);
            }
          };
          it.setOnClick(_function);
        }
      };
      XAjaxLink<Object> _doubleArrow_1 = ObjectExtensions.<XAjaxLink<Object>>operator_doubleArrow(_xAjaxLink, _function_1);
      MarkupContainer _addChild = this._wicketExtensionFactoryMethods.addChild(this, _doubleArrow_1);
      _xblockexpression = (_addChild);
    }
    return _xblockexpression;
  }
}
